package com.chinapost.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.chinapost.service.DqcdServiceI;
import com.chinapost.vo.Dqcd;
import com.chinapost.vo.Json;
import com.opensymphony.xwork2.ModelDriven;

@Namespace("/")
@Action(value = "dqcdAction", results = { @Result(name = "dqcdManager", location = "/jsp/dqcd/dqcdManager.jsp"),
		 @Result(name = "dqcdEdit", location = "/jsp/dqcd/dqcdEdit.jsp") 
	 })
public class DqcdAction extends BaseAction implements ModelDriven<Dqcd> {

	private DqcdServiceI dqcdService;
	private Dqcd dqcd = new Dqcd();


	public DqcdServiceI getDqcdService() {
		return dqcdService;
	}

	@Autowired
	public void setDqcdService(DqcdServiceI dqcdService) {
		this.dqcdService = dqcdService;
	}

	@Override
	public Dqcd getModel() {
		return dqcd;
	}

	public String dqcdManager() {
		return "dqcdManager";
	}

	public String dqcdEdit(){
		return "dqcdEdit";
	}
	
	public void edit(){
		Json j = new Json();
		try {
			dqcdService.edit(dqcd);
			j.setSuccess(true);
			j.setMsg("编辑成功!");
		} catch (Exception e) {
			j.setMsg("编辑失败！");
		}
		writeJson(j);
	}
	
	public void addDqcds() {
		Json j = new Json();
		int count = 0;
		try {
			count = dqcdService.addDqcds(dqcd);
			if (count > 0) {
				j.setSuccess(true);
				j.setMsg("上传成功，导入" + count + "条数据！");
			} else {
				j.setMsg("未导入任何数据！");
			}
		} catch (Exception e) {
			j.setMsg("上传失败,导入数据失败！");
		}
		super.writeJson(j);
	}

	public void datagrid() {
		super.writeJsonDate(dqcdService.datagrid(dqcd));
	}

}
